﻿using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.Model;

namespace Basic.FlowRemoteModel.EventTemplate.Model
{
    public class RpcBroadcastConfig
    {
        /// <summary>
        /// 指令
        /// </summary>
        [NullValidate("flow.event.rpc.dictate.null")]
        public string SysDictate
        {
            get;
            set;
        }
        /// <summary>
        /// 是否同步启动同步锁(解决客户端重复提交问题)
        /// </summary>
        public bool IsEnableLock { get; set; }


        /// <summary>
        /// 远程服务节点地址
        /// </summary>
        [EntrustValidate("_Check")]
        public string[] TypeVal
        {
            get;
            set;
        }
        /// <summary>
        /// 节点列表
        /// </summary>
        public long[] ServerId
        {
            get;
            set;
        }
        /// <summary>
        /// 是否限定唯一
        /// </summary>
        public bool IsOnly
        {
            get;
            set;
        }
        /// <summary>
        /// 广播方式
        /// </summary>
        [EnumValidate("flow.event.rpc.broadcastType.error", typeof(BroadcastType))]
        public BroadcastType BroadcastType
        {
            get;
            set;
        }
        private bool _Check ( RpcBroadcastConfig config, out string error )
        {
            if ( config.ServerId.IsNull() && config.TypeVal.IsNull() )
            {
                error = "flow.event.rpc.address.null";
                return false;
            }
            error = null;
            return true;
        }
    }
}
